{# **
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * #}
{% block translatable_choice_widget %}
  {% import '@PrestaShop/Admin/macros.html.twig' as ps %}

  {% set class = extraVars.class|default('') %}
  {% set rowAttributes = extraVars.row_attr|default({}) %}
  {% set attr = form.vars.attr %}
  {% set attr = attr|merge({class: (attr.class|default('') ~ ' custom-select translatable_choice')|trim}) %}
  <div class="form-group row type-choice {{ class }}" {% for key, rowAttr in rowAttributes %} {{ key }}="{{ rowAttr }}"{% endfor %}>
  {% set extraVars = extraVars|default({}) %}

  {# options selector #}
  {% for language, choices in form.vars.choices %}
    <div class="col-sm-6" {% if form.vars.default_locale is defined and form.vars.default_locale is not same as(language) %}style="display: none"{% endif %}>
      <select class="{{ attr.class }}" id="{{ form.vars.id ~ '_' ~ language }}" data-language="{{ language }}">
        {% for choiceValue, choiceLabel in choices %}
          <option value="{{ choiceValue }}"
            {% if value is defined and value[language] is defined and choiceValue is same as(value[language]) %} selected="selected"{% endif %}
             {% if form.vars.row_attr[language][choiceValue] is defined and form.vars.row_attr[language][choiceValue] is iterable %}{% for optionKey, optionAttr in form.vars.row_attr[language][choiceValue] %} {{ optionKey }}="{{ optionAttr }}"{% endfor %}{% endif %}>{{ choice_translation_domain is not defined or choice_translation_domain is same as(false) ? choiceLabel : choiceLabel|trans({}, choice_translation_domain) }}</option>
        {% endfor %}
      </select>
      <input type="hidden" id="{{ form.vars.id ~ '_' ~ language ~ '_value' }}" name="{{ form.vars.full_name ~ '[' ~ language ~ ']' }}" value="{{ choices|first }}" />
    </div>
  {% endfor %}

  {# languages selector #}
  {% if form.vars.locales is defined and form.vars.locales is not empty %}
    <div class="col-sm-3">
      <select name="{{ form.vars.id ~ '_language' }}" class="custom-select translatable_choice_language">
        {% if form.vars.locales is iterable %}
          {% for language in form.vars.locales %}
            <option value="{{ language.id_lang }}">{{ language.iso_code ~ ' - ' ~ language.name }}</option>
          {% endfor %}
        {% endif %}
      </select>
    </div>
  {% endif %}

  {# extra button #}
  {% if button is defined %}
    <div class="col-sm-3">
      <button type="button" {% if button.id is defined %}id="{{ button.id }}"{% endif %} class="btn {% if button.class is defined %}{{ button.class }}{% else %}btn-default{% endif %}" {% if button.action is defined %} onclick="{{ button.action }}"{% endif %}>
        {% if button.icon is defined %}<i class="material-icons">{{ button.icon }}</i>{% endif %}
        {{ button.label }}
      </button>
    </div>
  {% endif %}
  </div>

  {{- block('form_help') -}}
  {{- block('form_hint') -}}
{% endblock translatable_choice_widget %}
